package welsir.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import welsir.entity.dos.Square;
import welsir.entity.dos.SquareClass;
import welsir.entity.vo.ResultMessage;
import welsir.mapper.SquareClassMapper;
import welsir.mapper.SquareMapper;
import welsir.util.ResultUtil;

import javax.annotation.Resource;
import java.util.List;


@io.swagger.annotations.Api(tags = "Web圈子分类接口")
@RestController
@RequestMapping("/webSquareClass")
public class WebSquareClassController {

    @Resource
    private SquareMapper squareMapper;

    @Resource
    private SquareClassMapper squareClassMapper;

    @ApiOperation(value = "根据分类id获取文章数量")
    @ApiImplicitParam(name = "id",value = "id",required = true)
    @GetMapping("/getArticleClassNum/{id}")
    public ResultMessage<Integer> getArticleClassNum(
            @PathVariable("id") Integer id
    ){
        QueryWrapper<Square> wrapper= new QueryWrapper<>();
        wrapper.eq("sort_class", id);
        return ResultUtil.data(squareMapper.selectCount(wrapper));
    }

    @ApiOperation(value = "根据分类别名获取分类信息")
    @ApiImplicitParam(name = "otherName",value = "otherName",required = true)
    @GetMapping("/getArticleClassByOtherName/{otherName}")
    public ResultMessage<SquareClass> getArticleClassByOtherName(
            @PathVariable("otherName") String otherName
    ){
        QueryWrapper<SquareClass> wrapper= new QueryWrapper<>();
        wrapper.eq("other_name", otherName);
        return ResultUtil.data(squareClassMapper.selectOne(wrapper));
    }

    @ApiOperation(value = "获取全部分类列表")
    @GetMapping("/getSquareClassList")
    public ResultMessage<List<SquareClass>> getSquareClassList(
    ){
        return ResultUtil.data(squareClassMapper.selectList(null));
    }

}

